package com.yida.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import com.yida.common.core.domain.R;
import com.yida.system.api.RemoteUKeyUserService;
import com.yida.system.api.domain.SysUserUkey;

/**
 * 短信服务降级处理
 * 
 * @author hmh
 * @date 2022/10/26
 */
@Component
public class RemoteUKeyUserFallbackFactory implements FallbackFactory<RemoteUKeyUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUKeyUserFallbackFactory.class);

    @Override
    public RemoteUKeyUserService create(Throwable throwable) {
        log.error("UKey服务调用失败:{}", throwable.getMessage());
        return new RemoteUKeyUserService() {

            @Override
            public R<Boolean> ukeyValidate(SysUserUkey sSysUKeyUser, String source) {
                log.error(sSysUKeyUser.getUserName() + "：[" + sSysUKeyUser.getPin() + ":" + sSysUKeyUser.getSignUKeyStr() + "]校验UKey信息失败:{}" + throwable.getMessage());
                return R.fail(sSysUKeyUser.getUserName() + "：校验UKey信息失败:{}" + throwable.getMessage());
            }

            @Override
            public R<SysUserUkey> waitSignMsg(SysUserUkey sSysUKeyUser, String source) {
                log.error(sSysUKeyUser.getUserName() + "：[" + sSysUKeyUser.getUserName() + ":" + sSysUKeyUser.getPin() + "," + sSysUKeyUser.getRnd() + "]获取UKey验签信息失败:{}" + throwable.getMessage());
                return R.fail(sSysUKeyUser.getUserName() + "：[" + sSysUKeyUser.getUserName() + ":" + sSysUKeyUser.getPin() + "," + sSysUKeyUser.getRnd() + "]获取UKey验签信息失败:{}" + throwable.getMessage());
            }

        };
    }
}
